#include <eiq_api/libtf_eiq.h>
#include "image_data.h"

#include <string.h>
extern "C"{
	enum
	{
		kStatus_Fail = -1,
		kStatus_Success = 0,
	};
	
	uint8_t* MODEL_Run(){
		tensor_dims_t inputDims;
		tensor_type_t inputType;
		uint8_t* inputData = MODEL_GetInputTensorData(&inputDims, &inputType);

		tensor_dims_t outputDims;
		tensor_type_t outputType;
		uint8_t* outputData = MODEL_GetOutputTensorData(&outputDims, &outputType);	
		
		uint32_t h = inputDims.data[1], w = inputDims.data[2], c = inputDims.data[3];
		uint32_t is_processed = false;
		
		if(0 == GetImage(inputData, w, h, c, &is_processed)){
			if(!is_processed) MODEL_ConvertInput(inputData, &inputDims, inputType);
			MODEL_RunInference();
		}
		
		return outputData;
	}
	int MODEL_RunOD(){
		tensor_dims_t inputDims;
		tensor_type_t inputType;
		uint8_t* inputData = MODEL_GetInputTensorData(&inputDims, &inputType);
		
		uint32_t h = inputDims.data[1], w = inputDims.data[2], c = inputDims.data[3];
		uint32_t is_processed = false;
		
		if(0 == GetImage(inputData, w, h, c, &is_processed)){
			if(!is_processed) MODEL_ConvertInput(inputData, &inputDims, inputType);
			return MODEL_RunInference();
		}

		return kStatus_Success;
	}
	
	int MODEL_Invoke(){
		MODEL_RunOD();
		return kStatus_Success;
	}
}
